package com.xl.yygh.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xl.yygh.common.exception.YyghException;
import com.xl.yygh.common.result.ResultCodeEnum;
import com.xl.yygh.hosp.mapper.HospitalSetMapper;
import com.xl.yygh.hosp.service.HospitalSetService;
import com.xl.yygh.model.model.hosp.HospitalSet;
import com.xl.yygh.model.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

/**
 * @author XiangLiang
 * @date 2023/10/21 18:55
 * @description
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    /**
     * 通过其它系统传递过来的医院编码获取本系统的该医院签名
     *
     * @param hoscode 医院编码
     * @return 本系统该医院的签名
     */
    @Override
    public String getSignByHoscode(String hoscode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));
        if (hospitalSet.getSignKey().isEmpty()) {
            return null;
        }
        return hospitalSet.getSignKey();
    }

    /**
     * 获取医院签名信息
     *
     * @param hoscode 医院编号
     * @return 医院签名信息
     */
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
